#include<stdio.h>
int main()
{
    //freopen("in.txt","r",stdin);
    long long a;
    long long b;
    scanf("%lld %lld",&a,&b);
    long long r;
    while (a % b != 0)
    {
        r = a % b;
        a = b;
        b = r;
    }
    printf("%lld",b);    
}